package leecode

func goodsOrder(goods string) []string {
	var result []string
	goodArr := []byte(goods)
	visited := make([]bool, len(goodArr))
	path := make([]byte, 0)
	var backtracking157 func(path, goodArr []byte, visited []bool)
	backtracking157 = func(path, goodArr []byte, visited []bool) {
		if len(path) == len(goodArr) {
			temp := string(path)
			result = append(result, temp)
		}
		for i := 0; i < len(goodArr); i++ {
			if !visited[i] {
				path = append(path, goodArr[i])
				visited[i] = true
				backtracking157(path, goodArr, visited)
				visited[i] = false
				path = path[:len(path)-1]
			}
		}
		return
	}
	backtracking157(path, goodArr, visited)
	//对结果请求去重
	rightResult := make([]string, 0)
	hashMap := make(map[string]int)
	for _, value := range result {
		hashMap[value]++
	}
	for key, _ := range hashMap {
		rightResult = append(rightResult, key)
	}
	return rightResult
}
